﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace ConexionBD
{
    public partial class FormModNot : Form
    {
        MySqlConnection Conexion = new MySqlConnection();
        public string stConsulta;
        string opcion1;
        string opcion2;
        string opcion3;
        string titulo;
        string contenido;

        public FormModNot()
        {
            InitializeComponent();
        }

        private void FormModNot_Load(object sender, EventArgs e)
        {
            Nota noti = new Nota();
            DataTable dt = new DataTable();
            dt = noti.modNotaOne();
          
            try
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                    comboBox1.Items.Add(dt.Rows[i]["nombre_libreta"]);
            }

            catch (MySqlException error)
            {
                throw error;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int selectedIndex = comboBox1.SelectedIndex;
            Object selectedItem = comboBox1.SelectedItem;
            opcion1 = selectedItem.ToString();

           
            llenarCombo(opcion1);
        }
        public void llenarCombo(string opcion1)
        {
            opcion1 = "'" + opcion1 + "'";
            Nota notis = new Nota();
            DataTable dt2 = new DataTable();
            dt2 = notis.modNoteTwo(opcion1);

            try
            {
                for (int i = 0; i < dt2.Rows.Count; i++)
                    comboBox2.Items.Add(dt2.Rows[i]["titulo"]);
            }

            catch (MySqlException error)
            {
                throw error;
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            int selectedIndex2 = comboBox2.SelectedIndex;
            Object selectedItem2 = comboBox2.SelectedItem;
            opcion2 = selectedItem2.ToString();

          

            opcion3 = "'" + opcion2 + "'";
            Nota note = new Nota();
            DataTable dt3 = new DataTable();
            dt3 = note.modNoteTres(opcion3);
 
            richTextBox1.Text = dt3.Rows[0]["texto"].ToString();
            textBox1.Text = opcion2;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Nota notilla = new Nota();
            titulo = textBox1.Text;
            contenido = richTextBox1.Text;
            titulo = "'" + titulo + "'";
            contenido = "'" + contenido + "'";

            Object selectedItem = comboBox1.SelectedItem;


            string opcionT = selectedItem.ToString();
            Object selectedItem2 = comboBox2.SelectedItem;
            string opcionC = selectedItem2.ToString();
            opcionC = "'" + opcionC + "'";
            notilla.enviarModificarNota(titulo, contenido, opcionC);
           


        }


    }
}
